﻿using System;
using System.Web.UI.WebControls;
using Test.DAL;
using Test.IDAL;


namespace Test
{
    public partial class ClassInfo : System.Web.UI.Page
    {
        IClassInfoDAL bll = new ClassInfoDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            var result=bll.Select();
            if (result.States)
            {
                GridView1.DataSource = result.Data;
            }
           
            //GridView1.DataBind();
            Page.DataBind();// 所有执行
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //DataKeyNames="Id"
            var data = e.Keys["Id"];
            int id = Convert.ToInt32(data);
            var result = bll.Delete(new Model.ClassInfo() { Id = id });
            if (result.States && result.Data > 0)
            {
                var url = Request.Url.PathAndQuery;
                Response.Redirect(url);//重定向
            }
            else {
                Response.Write("<script>alert('"+result.message+"')</script>");
            }
        }
    }
}